import axios from 'axios'

const request = axios.create({
	timeout: 5000
})


request.interceptors.request.use(config => {
	config.headers['token'] = localStorage.getItem('token') || 'xxxx'
	return config
}, error => {
	return Promise.reject(error)
})


request.interceptors.response.use(response => {
	const { code } = response.data
	if(code === 404) {
		console.log('资源不存在')
	}

	if(code === 500) {
		console.log('服务器错误')
	}

	if(code === 401) {
		console.log('权限不够')
	}


	return response
}, error => {
	return Promise.reject(error)
})


export default request



